package com.tywj.panda.customer.common.tool

import android.text.TextUtils
import com.tywj.panda.customer.common.R
import com.tywj.lib.core.common.util.RegexUtil
import com.tywj.lib.core.common.util.ToastUtil

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/26
 *     desc   : 输入验证工具类
 *     version: 1.0.0
 * </pre>
 */
object InputVerifyTool {

    fun verifyPhone(phone: String): Boolean {

        if (TextUtils.isEmpty(phone)) {
            shortToast(R.string.common_verify_phone_is_empty)
            return false
        }

        if (!RegexUtil.isPhone(phone)) {
            shortToast(R.string.common_verify_phone_wrong)
            return false
        }

        return true
    }

    fun verifyCode(code: String): Boolean {

        if (TextUtils.isEmpty(code)) {
            shortToast(R.string.common_verify_code_is_empty)
            return false
        }

        if (code.length != 6) {
            shortToast(R.string.common_verify_code_wrong)
            return false
        }
        return true
    }

    fun verifyIdCard(idCard: String): Boolean {
        if (!RegexUtil.isIDCard18(idCard)) {
            shortToast(R.string.common_verify_id_card_wrong)
            return false
        }

        return true
    }


    private fun shortToast(id: Int) {
        ToastUtil.shortToast(id)
    }
}